package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.annotation.Query
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder
import java.sql.Timestamp
import java.time.LocalDateTime

/**
 * 公共查询类
 */

@JsonTypeName("RoleQueryCriteria")
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
data class RoleQueryCriteria(// 多字段模糊
    @Query(blurry = "name,remark") var blurry: String? = null,
    @Query(type = Query.Type.GREATER_THAN, propName = "createTime") var startTime: Timestamp? = null,
    @Query(type = Query.Type.LESS_THAN, propName = "createTime") var endTime: Timestamp? = null
) {
    annotation class Update

    companion object {
        fun fromJson(json: String): RoleQueryCriteria? {
            val obj=JacksonUtil.parseObject(json, RoleQueryCriteria::class.java)!!
            return when(obj){
                is RoleQueryCriteria -> obj
                else -> null
            }
        }
    }
    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: RoleQueryCriteria?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}